﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace API.Models.Repository
{
    public class RepositoryFactory<T> where T : class
    {
        public static IGenericRepository<T> Create()
        {
            var types = AppDomain.CurrentDomain.GetAssemblies().ToList()
                .SelectMany(s => s.GetTypes())
                .Where(r => typeof(IGenericRepository<T>).IsAssignableFrom(r));

            if (types == null)
            {
                throw new Exception("Репозиторий для метода не реализован");
            }

            return (IGenericRepository<T>)Activator.CreateInstance(types.FirstOrDefault());
        }
    }

    public class EXT_ATTACHMENTS_Repository : GenericRepository<PartnerDbContext, EXT_ATTACHMENTS> { }
    public class SEC_PERMISSIONS_Repository : GenericRepository<PartnerDbContext, SEC_PERMISSIONS> { }
    public class SEC_ROLES_Repository : GenericRepository<PartnerDbContext, SEC_ROLES> { }
    public class SEC_ROLE_PERMISSIONS_Repository : GenericRepository<PartnerDbContext, SEC_ROLE_PERMISSIONS> { }

    public class SEC_USERS_ROLES_Repository : GenericRepository<PartnerDbContext, SEC_USERS_ROLES> { }
    public class WH_ITEMS_CODES_Repository : GenericRepository<PartnerDbContext, WH_ITEMS_CODES> { }

    public class WH_INVOICE_LINE_TAXES_Repository : GenericRepository<PartnerDbContext, WH_INVOICE_LINE_TAXES> { }

}